/*
 * @description:
 * @version: 1.0.1
 * @Author: xuqiulin
 * @Date: 2021-06-16 16:40:14
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2021-06-17 10:40:26
 */
package main

import (
	"fmt"
	"net"
)

func main() {
	ln, err := net.Listen("tcp", ":8888")
	if err != nil {
		fmt.Println(err)
		return
	}
	for {
		conn, err := ln.Accept()
		if err != nil {
			fmt.Println(err)
			break
		}
		go handleConnection(conn)
	}
}

func handleConnection(conn net.Conn) {
	for {
		b := make([]byte, 512)
		n, err := conn.Read(b)
		if err != nil {
			return
		}
		fmt.Println("收到消息", string(b[:n]))
		n, err = conn.Write(b[:n])
		if err != nil {
			return
		}
		fmt.Println("发送成功...")
	}
}
